//
//  XMThreeViewController.m
//  gpos_app
//
//  Created by apple on 2018/8/13.
//  Copyright © 2018年 apple. All rights reserved.
//

#import "XMThreeViewController.h"
#import "Masonry.h"
#import "GPosAPI.h"
#import "SVProgressHUD.h"
#import "XMRegisterViewController.h"
#import "MJRefresh.h"
#import "ChuCunViewController.h"
#import "jymimaViewController.h"
#import "daiShiFangViewCell.h"
#import "ruleViewController.h"
#import "earningsMXViewController.h"
#import "minerModel.h"
#import "gengDuoListViewController.h"

@interface XMThreeViewController()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic,strong)UITableView * tableView;
@property (nonatomic,strong)UIView * headerBjView;
@property (nonatomic,strong)UIImageView * bjImgeView;
@property (nonatomic,strong)UIView * contentView;
@property (nonatomic,strong)UIView * daishifangView;
@property (nonatomic,strong)UILabel * yesterdaySY;
@property (nonatomic,strong)UILabel * zongChuCun;
@property (nonatomic,strong)UIButton * ycButton;
//@property (nonatomic,strong)NSString * zongCcGPOS;
@property (nonatomic,strong)UILabel * liXiTextLabel;
@property (nonatomic,strong)UILabel * personageTextLabel;
@property (nonatomic,strong)UIButton * chuCunButton;
@property (nonatomic,strong)NSDictionary * params;
@property (nonatomic,strong)NSString * ZongAmount;
@property (nonatomic,strong)NSString * Yesterday;
@property (nonatomic,strong)NSString * Extension;
@property (nonatomic,strong)NSString * Storage;
@property (nonatomic,strong)UIView * footherView;

@property (nonatomic,strong)NSMutableArray * modelArr;
@end


@implementation XMThreeViewController


-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    
    self.navigationController.navigationBar.hidden=YES;
    self.tabBarController.tabBar.hidden=NO;
    
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(walkVCClick:) name:@"buttonLoseRespon" object:nil];
    [self loadData];

}

- (void)walkVCClick:(NSNotification *)noti

{
    
    [self loadData];
}
-(void)dealloc{
    
    [[NSNotificationCenter defaultCenter] removeObserver:self];
    
}

//请求
- (void)loadData{
    [SVProgressHUD showWithStatus:@"加载中"];
    [SVProgressHUD setDefaultStyle:SVProgressHUDStyleDark];
    [SVProgressHUD setDefaultAnimationType:SVProgressHUDAnimationTypeFlat];
    __weak typeof(self) weakSelf = self;
    self.modelArr = [[NSMutableArray alloc] init];
    int user = [[[NSUserDefaults standardUserDefaults] objectForKey:@"userId"] intValue];
    self.params=[NSDictionary new];
    self.params = @{@"userId" : @(user)};
    dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
    // 创建全局并行
    dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
    dispatch_group_t group = dispatch_group_create();
    dispatch_group_async(group, queue, ^{
        
        // 请求一
        [GPosAPI requestViewHoldInfoWithParams:weakSelf.params andCallback:^(id obj) {
            NSLog(@"储存---%@",obj);
            if (obj == nil) {
                [self.tableView.mj_header endRefreshing];
                [self UIloadView];
            }else {
                
                if ([[obj objectForKey:@"code"] integerValue] ==200) {
                    
                    NSDictionary * dict= [obj objectForKey:@"data"];
                    NSDecimalNumber * number = [dict objectForKey:@"amount"];
//                    NSLog(@"----nuss--%@",number);
                    NSDecimalNumber * numberOne = [dict objectForKey:@"yesterday"];
                    NSDecimalNumber * numberTwo = [dict objectForKey:@"extension"];
                    NSDecimalNumber * numberThree = [dict objectForKey:@"storage"];
                    if ([[dict objectForKey:@"amount"] isMemberOfClass:[NSNull class]] ) {
                        
                        weakSelf.ZongAmount = @"0";
                    }else {
                        
                        //总储存
                        weakSelf.ZongAmount = [NSString stringWithFormat:@"%@",@(number.floatValue)];
                    }
                    
                    
                    if ([[dict objectForKey:@"yesterday"] isMemberOfClass:[NSNull class]] ) {
                        
                        weakSelf.Yesterday = @"0";
                    }else {
                        
                        // 昨日收益
                        weakSelf.Yesterday  = [NSString stringWithFormat:@"%@",@(numberOne.floatValue)];
                    }
                    
                    if ([[dict objectForKey:@"extension"] isMemberOfClass:[NSNull class]] ) {
                        
                        weakSelf.Extension = @"0";
                    }else {
                        
                        //推广收益
                        weakSelf.Extension = [NSString stringWithFormat:@"%@",@(numberTwo.floatValue)];
                    }
                    
                    if ([[dict objectForKey:@"storage"] isMemberOfClass:[NSNull class]] ) {
                        
                        weakSelf.Storage = @"0";
                    }else {
                        
                        //储存收益
                        weakSelf.Storage = [NSString stringWithFormat:@"%@",@(numberThree.floatValue)];
                    }
                    
                    
                }else if ([[obj objectForKey:@"code"] integerValue] ==401 || [[obj objectForKey:@"code"] intValue] == 402){
                    UIStoryboard *mainStory = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
                    [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"passWord"];
                    //storyboard里的ID
                    XMRegisterViewController *vc = [mainStory instantiateInitialViewController];
                    vc.navigationController.navigationBarHidden=NO;
                    //                    //设置当前窗口的根控制器
                    
                    [UIApplication sharedApplication].keyWindow.rootViewController=vc;
                    [SVProgressHUD showInfoWithStatus:[obj objectForKey:@"message"]];
                    [SVProgressHUD setDefaultStyle:SVProgressHUDStyleDark];
                    [SVProgressHUD setDefaultAnimationType:SVProgressHUDAnimationTypeFlat];
                    
                }else {
                    [self.tableView.mj_header endRefreshing];
                    [self UIloadView];
                    
                }
                
            }
            dispatch_semaphore_signal(semaphore);
        }];
        
    });
    
    dispatch_group_async(group, queue, ^{
        //余额
        NSDictionary * param = @{@"userId" : @(user),
                                 @"pageSize" : @(4),
                                 @"pageNum" : @(1)
                                 };
        [GPosAPI requestViewDetailListWithParams:param andCallback:^(id obj) {
            NSLog(@"储存列表---%@",obj);
            if (obj == nil) {
                
            }else {
                
                if ([[obj objectForKey:@"code"] integerValue] ==200) {
                    NSArray * arr = [[NSArray alloc] init];
                    arr = [obj objectForKey:@"data"];
                    for (NSDictionary * dic in arr) {
                        minerModel *model = [[minerModel alloc] init];
                        NSDecimalNumber * number = [dic objectForKey:@"actual"];
                        NSDecimalNumber * numbeOne = [dic objectForKey:@"bar"];
                        NSDecimalNumber * numberTwo = [dic objectForKey:@"storage"];
                        NSDecimalNumber * numberTw = [dic objectForKey:@"gain"];
                        model.actual = [NSString stringWithFormat:@"%@",@(number.floatValue)];
                        model.bar = [NSString stringWithFormat:@"%@",@(numbeOne.floatValue)];
                        model.created = [dic objectForKey:@"created"];
                        model.storage = [NSString stringWithFormat:@"%@",@(numberTwo.floatValue)];
                         model.gain = [NSString stringWithFormat:@"%@",@(numberTw.floatValue)];
                        [self.modelArr addObject:model];
                    }
                    [weakSelf.tableView reloadData];
                    [weakSelf.tableView.mj_header endRefreshing];
                }else if ([[obj objectForKey:@"code"] integerValue] ==401 || [[obj objectForKey:@"code"] intValue] == 402){
                    UIStoryboard *mainStory = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
                    [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"passWord"];
                    //storyboard里的ID
                    XMRegisterViewController *vc = [mainStory instantiateInitialViewController];
                    vc.navigationController.navigationBarHidden=NO;
                    //                    //设置当前窗口的根控制器
                    
                    [UIApplication sharedApplication].keyWindow.rootViewController=vc;
                    [SVProgressHUD showInfoWithStatus:[obj objectForKey:@"message"]];
                    [SVProgressHUD setDefaultStyle:SVProgressHUDStyleDark];
                    [SVProgressHUD setDefaultAnimationType:SVProgressHUDAnimationTypeFlat];
                    
                }else {
                    [weakSelf.tableView.mj_header endRefreshing];
                    [SVProgressHUD showErrorWithStatus:[obj objectForKey:@"message"]];
                    [SVProgressHUD setDefaultStyle:SVProgressHUDStyleDark];
                    [SVProgressHUD setDefaultAnimationType:SVProgressHUDAnimationTypeFlat];
                    
                }
                
            }
            
            dispatch_semaphore_signal(semaphore);
        }];
        
        
    });
    
    dispatch_group_notify(group, queue, ^{
        
        // 三个请求对应三次信号等待
        dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);
        dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);
        
        //在这里 进行请求后的方法，回到主线程
        dispatch_async(dispatch_get_main_queue(), ^{
            [SVProgressHUD dismiss];
            //更新UI操作
            
            [self UIloadView];
        });
        
        
    });
    
}

//主UI
- (void)UIloadView{
    self.tableView = [[UITableView alloc] init];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.backgroundColor = [UIColor colorWithRed:244/255.0f green:244/255.0f blue:244/255.0f alpha:1];;
//    //    //判断网络状态
//    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(doWork:) name:@"netStatus" object:nil];
//
    self.tableView.mj_header=[MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(loadData)];
    
    
    [self.view addSubview:self.tableView];
    if (iPhoneX) {
        [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.view).with.offset(0);
            make.top.equalTo(self.view).with.offset(-44);
            make.right.equalTo(self.view).with.offset(0);
            make.bottom.equalTo(self.view).with.offset(-kSystemNavHeight);
        }];
        
    }else {
        [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.view).with.offset(0);
            make.top.equalTo(self.view).with.offset(0);
            make.right.equalTo(self.view).with.offset(0);
            make.bottom.equalTo(self.view).with.offset(-kSystemNavHeight);
        }];
    }
    [self headerViewLoad];
    self.footherView = [[UIView alloc] init];
    
    //缺省图
    if (self.modelArr.count == 0) {
        self.footherView.frame = CGRectMake(0, 0, KmainScreenWidth, 240);
        self.footherView.backgroundColor = [UIColor colorWithRed:244/255.0f green:244/255.0f blue:244/255.0f alpha:1];
        self.tableView.tableFooterView = self.footherView;
        UIView * qstView = [[UIView alloc] init];
        qstView.backgroundColor = [UIColor colorWithRed:244/255.0f green:244/255.0f blue:244/255.0f alpha:1];
        [self.footherView addSubview:qstView];
        [qstView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.footherView).with.offset(0);
            make.left.equalTo(self.footherView).with.offset(0);
            make.right.equalTo(self.footherView).with.offset(0);
            make.bottom.equalTo(self.footherView.mas_bottom).with.offset(0);
        }];
        UIImageView * qstImage = [[UIImageView alloc] init];
        qstImage.image = [UIImage imageNamed:@"icon_wshuju"];
        [qstView addSubview:qstImage];
        [qstImage mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(qstView);
            make.centerY.equalTo(qstView);
        }];
        
        UILabel * qstLabel = [[UILabel alloc] init];
        qstLabel.text = @"暂无数据";
        qstLabel.textColor = [UIColor grayColor];
        qstLabel.font = [UIFont systemFontOfSize:15];
        [qstView addSubview:qstLabel];
        [qstLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(qstView);
            make.top.equalTo(qstImage.mas_bottom).with.offset(5);
        }];
        return;
    }
    
    self.footherView.frame = CGRectMake(0, 0, KmainScreenWidth, 40);
    self.footherView.backgroundColor = [UIColor colorWithRed:244/255.0f green:244/255.0f blue:244/255.0f alpha:1];
    self.tableView.tableFooterView = self.footherView;
    //查看更多
    UIButton * gengduoList = [UIButton buttonWithType:UIButtonTypeCustom];
    [gengduoList setTitle:@"查看更多" forState:UIControlStateNormal];
    gengduoList.titleLabel.font = [UIFont systemFontOfSize:15];
    [gengduoList setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
    [gengduoList addTarget:self action:@selector(gengduoListAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.footherView addSubview:gengduoList];
    [gengduoList mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.footherView).with.offset(2);
        make.centerX.equalTo(self.footherView);
    }];
    
    if (self.modelArr.count == 4) {
        self.footherView.hidden = NO;

    }else {
        self.footherView.hidden = YES;
        self.footherView = [[UIView alloc] init];
        self.footherView.backgroundColor = [UIColor colorWithRed:244/255.0f green:244/255.0f blue:244/255.0f alpha:1];
        self.tableView.tableFooterView = self.footherView;
    }
    
    
}

- (void)headerViewLoad{
    self.headerBjView = [[UIView alloc] init];
    if (IS_IPHONE5) {
        
        self.headerBjView.frame = CGRectMake(0, 0, KmainScreenWidth, 370);
        
    }else if (iPhoneX) {
        self.headerBjView.frame = CGRectMake(0, 0, KmainScreenWidth, 480);
        
    }else {
        self.headerBjView.frame = CGRectMake(0, 0, KmainScreenWidth, 450);
        
    }
    self.headerBjView.backgroundColor = [UIColor colorWithRed:244/255.0f green:244/255.0f blue:244/255.0f alpha:1];
    self.headerBjView.userInteractionEnabled = YES;
    self.tableView.tableHeaderView = self.headerBjView;
    
    self.bjImgeView = [[UIImageView alloc] init];
    //开启按钮的点击
    self.bjImgeView.userInteractionEnabled = YES;
    self.bjImgeView.image = [UIImage imageNamed:@"beijing_c"];
    [self.headerBjView addSubview:self.bjImgeView];
    if (iPhoneX) {
        
        [self.bjImgeView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.headerBjView).with.offset(0);
            make.left.equalTo(self.headerBjView).with.offset(0);
            make.right.equalTo(self.headerBjView).with.offset(0);
            
        }];
        
    }else if(IS_IPHONE5) {
       
        [self.bjImgeView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.headerBjView).with.offset(-20);
            make.left.equalTo(self.headerBjView).with.offset(0);
            make.right.equalTo(self.headerBjView).with.offset(0);
            make.height.equalTo(@200);
            
        }];
    }else {
        
       
        [self.bjImgeView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.headerBjView).with.offset(-20);
            make.left.equalTo(self.headerBjView).with.offset(0);
            make.right.equalTo(self.headerBjView).with.offset(0);
            
        }];
    }
    
    self.contentView = [[UIView alloc] init];
    self.contentView.backgroundColor = [UIColor whiteColor];
    self.contentView.layer.cornerRadius = 5;
    [self.headerBjView addSubview:self.contentView];
    if (IS_IPHONE5) {
        [self.contentView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.bjImgeView.mas_top).with.offset(80);
            make.left.equalTo(self.headerBjView).with.offset(15);
            make.right.equalTo(self.headerBjView).with.offset(-15);
            make.height.equalTo(@240);
        }];
        
    }else {
        [self.contentView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.bjImgeView.mas_top).with.offset(120);
            make.left.equalTo(self.headerBjView).with.offset(15);
            make.right.equalTo(self.headerBjView).with.offset(-15);
            make.height.equalTo(@278);
        }];
        
    }
    
    self.daishifangView = [[UIView alloc] init];
    self.daishifangView.backgroundColor = [UIColor whiteColor];
    [self.headerBjView addSubview:self.daishifangView];
    [self.daishifangView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.headerBjView.mas_bottom).with.offset(-1);
        make.left.equalTo(self.headerBjView).with.offset(0);
        make.right.equalTo(self.headerBjView).with.offset(0);
        make.height.equalTo(@50);
    }];
    
    [self contentLoadView];
    
    UIImageView * dsfimage = [[UIImageView alloc] init];
    dsfimage.image = [UIImage imageNamed:@"icon_shifang"];
    [self.daishifangView addSubview:dsfimage];
    [dsfimage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.daishifangView);
        make.left.equalTo(self.daishifangView).with.offset(15);
    }];
    
    UILabel * dsfLabel = [[UILabel alloc] init];
    dsfLabel.text = @"待释放";
    dsfLabel.font = [UIFont systemFontOfSize:16];
    [self.daishifangView addSubview:dsfLabel];
    [dsfLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.daishifangView);
        make.left.equalTo(dsfimage.mas_right).with.offset(10);
    }];
    
    
    UIButton * shouqiButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [shouqiButton setBackgroundImage:[UIImage imageNamed:@"icon_mx_l"] forState:UIControlStateNormal];
    [self.daishifangView addSubview:shouqiButton];
    [shouqiButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.daishifangView);
        make.right.equalTo(self.daishifangView).with.offset(-15);
    }];
    [shouqiButton addTarget:self action:@selector(shouqiButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    
    //规则问号
    UIButton * ruleButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [ruleButton setBackgroundImage:[UIImage imageNamed:@"icon_bangzhu"] forState:UIControlStateNormal];
    [self.headerBjView addSubview:ruleButton];
    [ruleButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.contentView.mas_top).with.offset(-20);
        make.right.equalTo(self.headerBjView).with.offset(-15);
    }];
    [ruleButton addTarget:self action:@selector(ruleButtonAction:) forControlEvents:UIControlEventTouchUpInside];
}

//content
- (void)contentLoadView{
    UILabel * yesterdayLabel = [[UILabel alloc] init];
    yesterdayLabel.text = @"昨日收益(GPOS)";
    yesterdayLabel.font = [UIFont systemFontOfSize:14];
    yesterdayLabel.textColor = [UIColor colorWithRed:88/255.0f green:113/255.0f blue:255/255.0f alpha:1];
    [self.contentView addSubview:yesterdayLabel];
    
    if (IS_IPHONE5) {
        [yesterdayLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.contentView).with.offset(20);
            make.centerX.equalTo(self.contentView);
        }];
    }else {
        
        [yesterdayLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.contentView).with.offset(26);
            make.centerX.equalTo(self.contentView);
        }];
    }
    
    
    self.yesterdaySY = [[UILabel alloc] init];
    self.yesterdaySY.textColor = [UIColor colorWithRed:88/255.0f green:113/255.0f blue:255/255.0f alpha:1];
    self.yesterdaySY.font = [UIFont fontWithName:@"Helvetica-Bold" size:28];
    self.yesterdaySY.textAlignment = NSTextAlignmentCenter;
    self.yesterdaySY.text = self.Yesterday;
    self.yesterdaySY.numberOfLines = 2;
    [self.contentView addSubview:self.yesterdaySY];
    [self.yesterdaySY mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(yesterdayLabel.mas_bottom).with.offset(16);
        make.left.equalTo(self.contentView).with.offset(10);
        make.right.equalTo(self.contentView).with.offset(-10);
    }];
    
    self.zongChuCun = [[UILabel alloc] init];
    self.zongChuCun.textColor = [UIColor colorWithRed:88/255.0f green:113/255.0f blue:255/255.0f alpha:1];
    self.zongChuCun.font = [UIFont systemFontOfSize:14];
//    NSString * str = @"5.00";
    self.zongChuCun.text = [NSString stringWithFormat:@"总储存 %@ GPOS",self.ZongAmount];
    [self.contentView addSubview:self.zongChuCun];
    if (IS_IPHONE5) {
        [self.zongChuCun mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.yesterdaySY.mas_bottom).with.offset(10);
            make.centerX.equalTo(self.yesterdaySY);
            //        make.left.equalTo(self.contentView).with.offset(10);
            //        make.right.equalTo(self.contentView).with.offset(-10);
        }];
    }else {
        
        [self.zongChuCun mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.yesterdaySY.mas_bottom).with.offset(15);
            make.centerX.equalTo(self.yesterdaySY);
            //        make.left.equalTo(self.contentView).with.offset(10);
            //        make.right.equalTo(self.contentView).with.offset(-10);
        }];
    }
   
    
    
    self.ycButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.contentView addSubview:self.ycButton];
    [self.ycButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.zongChuCun);
        make.left.equalTo(self.zongChuCun.mas_right).with.offset(5);
    }];
   [self.ycButton setImage:[UIImage imageNamed:@"icon_yangjingl"] forState:UIControlStateNormal];
    [self.ycButton addTarget:self action:@selector(ycbuttonAction:) forControlEvents:(UIControlEventTouchUpInside)];
    
    UIView  * shugang = [[UIView alloc] init];
    shugang.backgroundColor = [UIColor grayColor];
    [self.contentView addSubview:shugang];
    if (IS_IPHONE5) {
        [shugang mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.zongChuCun.mas_bottom).with.offset(15);
            make.centerX.equalTo(self.contentView);
            make.width.equalTo(@1);
            make.height.equalTo(@35);
        }];
    }else {
        
        [shugang mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.zongChuCun.mas_bottom).with.offset(30);
            make.centerX.equalTo(self.contentView);
            make.width.equalTo(@1);
            make.height.equalTo(@35);
        }];
    }
    
    
    UILabel * liXiLabel = [[UILabel alloc] init];
    liXiLabel.textColor = [UIColor grayColor];
    liXiLabel.text = @"储存收益";
    liXiLabel.font = [UIFont systemFontOfSize:14];
    liXiLabel.textAlignment = NSTextAlignmentCenter;
    [self.contentView addSubview:liXiLabel];
    if (IS_IPHONE5) {
        [liXiLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.zongChuCun.mas_bottom).with.offset(15);
            make.left.equalTo(self.contentView).with.offset(10);
            make.right.equalTo(shugang.mas_left).with.offset(-10);
        }];
    }else {
        
        [liXiLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.zongChuCun.mas_bottom).with.offset(30);
            make.left.equalTo(self.contentView).with.offset(10);
            make.right.equalTo(shugang.mas_left).with.offset(-10);
        }];
    }
    
    
    self.liXiTextLabel = [[UILabel alloc] init];
    self.liXiTextLabel.textColor = [UIColor blackColor];
    self.liXiTextLabel.text = self.Storage;
    self.liXiTextLabel.font = [UIFont systemFontOfSize:14];
    self.liXiTextLabel.textAlignment = NSTextAlignmentCenter;
    [self.contentView addSubview:self.liXiTextLabel];
    [self.liXiTextLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(liXiLabel.mas_bottom).with.offset(5);
        make.left.equalTo(self.contentView).with.offset(10);
        make.right.equalTo(shugang.mas_left).with.offset(-10);
    }];
    
    UILabel * personageLabel = [[UILabel alloc] init];
    personageLabel.textColor = [UIColor grayColor];
    personageLabel.text = @"推广收益";
    personageLabel.font = [UIFont systemFontOfSize:14];
    personageLabel.textAlignment = NSTextAlignmentCenter;
    [self.contentView addSubview:personageLabel];
    if (IS_IPHONE5) {
        [personageLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.zongChuCun.mas_bottom).with.offset(15);
            make.left.equalTo(shugang.mas_right).with.offset(10);
            make.right.equalTo(self.contentView).with.offset(-10);
        }];
    }else {
        
        [personageLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.zongChuCun.mas_bottom).with.offset(30);
            make.left.equalTo(shugang.mas_right).with.offset(10);
            make.right.equalTo(self.contentView).with.offset(-10);
        }];
    }
    
    
    self.personageTextLabel = [[UILabel alloc] init];
    self.personageTextLabel.textColor = [UIColor blackColor];
    self.personageTextLabel.text = self.Extension;
    self.personageTextLabel.font = [UIFont systemFontOfSize:14];
    self.personageTextLabel.textAlignment = NSTextAlignmentCenter;
    [self.contentView addSubview:self.personageTextLabel];
    [self.personageTextLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(personageLabel.mas_bottom).with.offset(5);
        make.left.equalTo(shugang.mas_right).with.offset(10);
        make.right.equalTo(self.contentView).with.offset(-10);
    }];
    
    
    self.chuCunButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.chuCunButton setTitle:@"储存" forState:UIControlStateNormal];
    self.chuCunButton.titleLabel.font = [UIFont systemFontOfSize:15];
    [self.chuCunButton setBackgroundImage:[UIImage imageNamed:@"icon_anniu_jx"] forState:UIControlStateNormal];
    [self.contentView addSubview:self.chuCunButton];
    if (IS_IPHONE5) {
        [self.chuCunButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(shugang.mas_bottom).with.offset(10);
            make.centerX.equalTo(self.contentView);
        }];
    }else {
        
        [self.chuCunButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(shugang.mas_bottom).with.offset(15);
            make.centerX.equalTo(self.contentView);
        }];
    }
    
    [self.chuCunButton addTarget:self action:@selector(chuCunButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    
}


- (void)ycbuttonAction:(UIButton *)sender {
    
    if ([self.zongChuCun.text rangeOfString:@"****"].location !=NSNotFound) {

        [self.ycButton setImage:[UIImage imageNamed:@"icon_yangjingl"] forState:UIControlStateNormal];
        NSString * str = self.ZongAmount;
        self.zongChuCun.text = [NSString stringWithFormat:@"总储存 %@ GPOS",str];
        
    } else {

        [self.ycButton setImage:[UIImage imageNamed:@"icon_biyan_l"] forState:UIControlStateNormal];
        NSString * str = @"****";
        self.zongChuCun.text = [NSString stringWithFormat:@"总储存 %@ GPOS",str];
        

    }
    
}


//储存按钮
- (void)chuCunButtonAction:(UIButton *)sender {
    
    if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"status"] intValue] ==2 ) {
        jymimaViewController * jymimaVC = [[jymimaViewController alloc] init];
         jymimaVC.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:jymimaVC animated:YES];
         jymimaVC.hidesBottomBarWhenPushed = NO;
    }else if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"status"] intValue] ==1 ){
        
        ChuCunViewController * VC = [[ChuCunViewController alloc] init];
        VC.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:VC animated:YES];
        VC.hidesBottomBarWhenPushed  = NO;
        
    }
    
}

//规则按钮
- (void)ruleButtonAction:(UIButton *)sender{
    ruleViewController * VC = [[ruleViewController alloc] init];
    VC.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:VC animated:YES];
    VC.hidesBottomBarWhenPushed = NO;
    
}

//待释放收益明细
- (void)shouqiButtonAction:(UIButton *)sender {
    earningsMXViewController *VC = [[earningsMXViewController alloc] init];
    VC.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:VC animated:YES];
    VC.hidesBottomBarWhenPushed= NO;
    
}

//查看更多
- (void)gengduoListAction:(UIButton *)sender{
    gengDuoListViewController *VC = [[gengDuoListViewController alloc] init];
    VC.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:VC animated:YES];
    VC.hidesBottomBarWhenPushed = NO;
    
    
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if (self.modelArr.count == 0) {
        return 0;
    }else {
        
       return self.modelArr.count;
    }
}



- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{//rankingCell
    
    
    daiShiFangViewCell * cell = [[daiShiFangViewCell alloc] init];
    
    cell = [tableView dequeueReusableCellWithIdentifier:@"daishifangCell"];
    if (!cell) {
        cell = [[[NSBundle mainBundle] loadNibNamed:@"daiShiFangViewCell" owner:self options:nil] firstObject];
    }
    
    //渐变色
    CAGradientLayer *gradientLayer = [CAGradientLayer layer];
    gradientLayer.frame = CGRectMake(0, 0, 130, 5);
    //设置渐变颜色数组,可以加透明度的渐变
    gradientLayer.colors = @[(__bridge id)[UIColor colorWithWhite:0 alpha:0.3].CGColor,(__bridge id)[UIColor colorWithWhite:0 alpha:1].CGColor];
    //设置渐变区域的起始和终止位置（范围为0-1）
    gradientLayer.startPoint = CGPointMake(1, 0);
    gradientLayer.endPoint = CGPointMake(0.5, 0);
    //设置蒙版，用来改变layer的透明度
    [cell.progressView.layer setMask:gradientLayer];
    
    
    cell.topLabel.text = [NSString stringWithFormat:@"%@（实存:%@ 放大:%@倍）",[self.modelArr[indexPath.row] storage],[self.modelArr[indexPath.row] actual],[self.modelArr[indexPath.row] gain]];
    
    // timeStampString 是服务器返回的13位时间戳
    NSString *timeStampString  = [self.modelArr[indexPath.row] created];
    
    // iOS 生成的时间戳是10位
    NSTimeInterval interval=[timeStampString doubleValue] / 1000.0;
    NSDate *date  = [NSDate dateWithTimeIntervalSince1970:interval];
    
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    NSString *dateString    = [formatter stringFromDate: date];

    cell.bottomLabel.text = dateString;
    double num = (double)[[self.modelArr[indexPath.row] bar] doubleValue]*100;
    NSString * str = @"%";
    cell.progressView.progress = [self.modelArr[indexPath.row] bar].floatValue;
//    NSLog(@"---cueng--%f",[self.modelArr[indexPath.row] bar].floatValue);
    cell.baifenbiLabel.text = [NSString stringWithFormat:@"%@%@",@((float)num).description,str];
    return cell;
}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return 70;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    NSLog(@"点击事件");
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
